<template>
  <div>
    <el-dialog title="开票管理" v-model="showDialog" :width="dialogWidth" :close-on-click-modal="false">
      <div class="bigTitle">开票管理</div>
      <el-form label-width="120px" class="baseForm" :model="form" ref="baseForm">
        <el-form-item label="开票名称" class="item">
          {{ form.name }}
        </el-form-item>
        <el-form-item label="开票日期" class="item">
          {{ form.invoiceDate.slice(0, 10) }}
        </el-form-item>
        <el-form-item label="客户名称" class="item">
          {{ form.customerName }}
        </el-form-item>
        <el-form-item label="发票类型" class="item">
          {{ form.invoiceTypeName }}
        </el-form-item>
        <el-form-item label="开票金额" class="item" prop="money">{{ form.money }}元</el-form-item>

        <el-form-item label="开票人" class="item">
          {{ form.tickerName }}
        </el-form-item>
        <el-form-item label="归属部门" class="item">
          {{ form.orgName }}
        </el-form-item>
        <el-form-item label="纳税人识别号" class="item">
          {{ form.taxNumber }}
        </el-form-item>
      </el-form>
      <div class="bigTitle">发票产品信息</div>
      <el-table :data="tables" border class="table" ref="multipleTable" header-cell-class-name="table-header">
        <el-table-column prop="productCode" label="产品编号" width="180"></el-table-column>
        <el-table-column prop="productName" label="产品名称"></el-table-column>
        <el-table-column prop="price" label="产品单价" width="100" :formatter="priceformatter"></el-table-column>
        <el-table-column prop="productSpec" label="产品规格"></el-table-column>
        <el-table-column label="产品数量" width="100" prop="productCount" :formatter="countformatter"></el-table-column>
        <el-table-column prop="money" label="总金额" :formatter="moneyformatter" width="140"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
const defaultdata = {
  name: '',
  invoiceDate: '',
  customerId: 0,
  customerName: '',
  invoiceTypeId: 0,
  invoiceTypeName: '',
  money: 0,
  tickerId: 0,
  tickerName: '',
  orgId: 0,
  orgName: '',
  taxNumber: '',
}
export default {
  data() {
    return {
      form: Object.assign({}, defaultdata),
      showDialog: false,
      dialogWidth: window.innerWidth > 768 ? '80%' : '100%',
      products: [],
      filemsgs: [],
      types: [],
      tables: [],
    }
  },
  methods: {
    show(id) {
      this.$api.invoice.find(id).then(({ msg }) => {
        this.form = msg
        this.tables = msg.products
        this.showDialog = true
      })
    },
    priceformatter(...arr) {
      const unit = arr[0].productUnit
      return arr[2] + '元' + (unit ? `/${unit}` : '')
    },
    countformatter(...arr) {
      const unit = arr[0].productUnit
      return arr[2] + (unit ? `${unit}` : '')
    },
    moneyformatter(...arr) {
      return arr[2] + '元'
    },
  },
}
</script>
<style lang="scss" scoped>
@media (max-width: 778px) {
  .baseForm {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
  }
}
@media (min-width: 778px) {
  .baseForm {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
}

.bigTitle {
  font-size: 18px;
  text-indent: 40px;
  padding: 20px 0;
  font-weight: bold;
  border-bottom: 1px solid #ddd;
  margin-bottom: 10px;
  background: #00000005;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
</style>
